﻿using System;
using System.Collections.Generic;

namespace Pixels.Logic
{
    public class Colonist : IComparable<Colonist>
    {

        private readonly Colony myColony;

        public Colonist(Colony colony, Type t) {
            this.myColony = colony;
            this.MyOccupation = t;
        }

        private Structure _struct;
        public Structure AssignedToStructure {
            get {
                return _struct;
            }
            set {
                if (_struct != null) _struct.loseColonist(this);
                _struct = value;
                if (_struct != null) _struct.gainColonist(this);
                if (_struct == null) myColony.idleColonists.Add(this);
                else                 myColony.idleColonists.Remove(this);
            }
        }


        public enum Type
        {
            colonist,
            technician,
            soldier
        }

        private Type myOccupation;
        public Type MyOccupation { 
            get { return myOccupation;  }
            set { myOccupation = value; }
        }

        public void die() {
            myColony.removeColonist(this);
        }


        int IComparable<Colonist>.CompareTo(Colonist other) {
            return Ur.Maths.sgn((int)myOccupation - (int)other.myOccupation);

        }

        
    }
}